﻿<%@ Page Title="" Language="C#" MasterPageFile="~/NewTemplate.Master" AutoEventWireup="true" CodeBehind="ViewEvent.aspx.cs" Inherits="PresentationLayer.ViewEvent" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">

    <style type="text/css">
        .EventDetails 
        {
            margin-top: 10px;
        }
        .EventDetails td
        {
            vertical-align: top;
            padding-bottom: 0px;
        }
        .Col1 
        {
            width: 100px;
        }
        .SectionHeader 
        {
            font-size:16px;
            font-weight:bold;
            padding:5px 0px;
        }
        .HiddenRows 
        {
            display:none;
            visibility: hidden;
        }
        p.LocationInfo
        {
            margin:0px 0px 10px 0px;
        }
        p.OptionName 
        {
            font-weight: bold;
            margin:5px 0px 5px 0px;
        }
        .VoteButton 
        {
            margin-top:2px;
            margin-bottom:5px;
            margin-left:15px;
        }
        #Map 
        {
            width: 300px;
            height: 250px;
            float:right;
            border: 1px solid #000000;
        }
        
        #slideContainer_invite
        {
	        visibility: hidden;
	        height:1px; 
	        overflow:hidden;
	        display:none;
	        
	  
        }
        #slideContent_invite
        {
            padding: 1px;
          }
        .style1
        {
            font-size: 16px;
        }
    </style>
   <script src="javascript/Sliding.js" type="text/javascript" language="javascript">  </script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" language="javascript">
        var geocoder;
        var map;
        var markersArray = [];

        function initializeMap() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(56, 11);
            var myOptions = {
                zoom: 10,
                center: latlng,
                mapTypeControl: true,
                mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
                navigationControl: true,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("Map"), myOptions);

            var elements = document.getElementsByTagName("p");
            for (i = 0; i < elements.length; i++) {
                if (elements[i].getAttribute('class') == "LocationInfo") {
                    var text = elements[i].innerHTML;
                    var splitText = text.split("<br>\n");
                    var address = splitText[0].trim() + ", " + splitText[1].trim();

                    var element2 = elements[i].parentNode;
                    var contentText = element2.innerHTML;

                    var element3 = elements[i].previousSibling.previousSibling;
                    var title = element3.innerHTML;
                    showAddress(address, contentText, title);
                }
            }

        }

        function showAddress(address, contentText, title) {

            if (markersArray) {
                for (i in markersArray) {
                    markersArray[i].setMap(null);
                }
                markersArray.length = 0;
            }

            if (geocoder) {
                geocoder.geocode({ 'address': address }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                            map.setCenter(results[0].geometry.location);

                            var infowindow = new google.maps.InfoWindow({ 
                                content: contentText
	                        });
                            var marker = new google.maps.Marker({
                                position: results[0].geometry.location,
                                map: map,
                                title: title
                            });
                            google.maps.event.addListener(marker, 'click', function () {
                                infowindow.open(map, marker);
                            });

                            markersArray.push(marker);
                        } else {
                            alert("No results found");
                        }
                    } else {
                        alert("Geocode was not successful for the following reason: " + status);
                    }
                });
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlace" runat="server">

    <h1><asp:Label ID="eventName" runat="server" Text="" align="center"></asp:Label></h1>
    <span>Created by <asp:Label ID="eventCreator" runat="server"></asp:Label> | <asp:Label ID="eventVisibility" runat="server"></asp:Label> </span>
    <br /><br />
    <asp:Button ID="AttendingButtom" visible="true" runat="server" OnClick="Attending" Text="I will Attend"/>
    <a> &nbsp &nbsp </a>
    <asp:Button ID="NotAttendingButtom" visible="true" runat="server" OnClick="NotAttending" Text="I won't Attend"/>
    <div id="Map"></div>

    <table class="EventDetails">
        <colgroup>
            <col class="Col1" />
            <col class="Col2" />                        
            <col class="Col3" />
        </colgroup>
        <tr>
            <td rowspan="2" class="SectionHeader" id="LocationHeader" runat="server">Location</td>
            <td class="HiddenRows"></td>
            <td class="HiddenRows"></td>
        </tr>
        <asp:ObjectDataSource ID="LocationsSource" runat="server" SelectMethod="GetLocations"
            TypeName="PresentationLayer.ViewEvent" ViewStateMode="Enabled">
        </asp:ObjectDataSource>
        <asp:ListView ID="LocationsView" runat="server" DataSourceID="LocationsSource" ClientIDMode="Static"
            ViewStateMode="Disabled" style="text-align: left">
            <ItemTemplate>
                <tr>
                    <td>
                        <p class="OptionName"><%#Eval("LocationPlace")%></p>
                        <p class="LocationInfo">
                            <%#Eval("Address")%> <br />
                            <%#Eval("Country")%> ,  <%#Eval("City")%>
                        </p>
                    </td>
                    <td>
                        <asp:Button ID="LocationButton" runat="server"  Text="Vote This" OnClick="ButtonVoteLocation"
                                    OnPreRender="ButtonsLoad" location=<%#Eval("idlocation")%> ClientIDMode="Static" class="VoteButton" />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
            </LayoutTemplate>
        </asp:ListView>
        <tr>
            <td rowspan="2" class="SectionHeader" id="DateHeader" runat="server">Date</td>
            <td class="HiddenRows"></td>
            <td class="HiddenRows"></td>
        </tr>
        <asp:ObjectDataSource ID="DatesSource" runat="server" SelectMethod="GetDates" 
            TypeName="PresentationLayer.ViewEvent">
        </asp:ObjectDataSource>
        <asp:ListView ID="DatesView" runat="server" DataSourceID="DatesSource">
            <ItemTemplate>
                <tr>
                    <td>
                        <p class="OptionName"><asp:Label ID="DateLabel" runat="server" OnPreRender="DateLabel" date=<%#Eval("Date")%> ></asp:Label></p>
                    </td>
                    <td>
                        <asp:Button ID="DateButton" runat="server" OnClick="ButtonVoteDate" Text="Vote This"
                                    OnPreRender="ButtonsLoad" ClientIDMode="Static" date=<%#Eval("Date")%> class="VoteButton" />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
            </LayoutTemplate>
        </asp:ListView>
        <tr>
            <td rowspan="2" class="SectionHeader" id="TimeHeader" runat="server">Time</td>
            <td class="HiddenRows"></td>
            <td class="HiddenRows"></td>
        </tr>
        <asp:ObjectDataSource ID="TimesSource" runat="server" SelectMethod="GetTimes" 
            TypeName="PresentationLayer.ViewEvent">
        </asp:ObjectDataSource>
        <asp:ListView ID="TimesView" runat="server" DataSourceID="TimesSource">
            <ItemTemplate>
                <tr>
                    <td>
                        <p class="OptionName"><%#Eval("Time")%></p>
                    </td>
                    <td>
                        <asp:Button ID="TimeButton" runat="server" OnClick="ButtonVoteTime" Text="Vote This"
                                    OnPreRender="ButtonsLoad" ClientIDMode="Static" time=<%#Eval("Time")%> class="VoteButton" />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
            </LayoutTemplate>
        </asp:ListView>
    </table>
    <div id="invitemenu" visible="false" runat="server">
        <br />
        <span class="style1"><strong> Invite People:</strong></span>
        <br />
        <br />
        <b>Write the username of the user that you want to invite:</b> </br>
        <asp:TextBox ID="invite_username" runat="server"></asp:TextBox>
        <asp:Button ID="invite_buttom" Text="Invite" runat="server" OnClick="Invite"/>
               
       
        
    </div>
    <asp:Button ID="Delete" Text="Delete Event" runat="server" OnClick="DeleteEvent" Visible="false"/>
    <div id="attendance" runat="server">
        <h3>Attending guests</h3>
        <asp:Repeater ID="attendance_repeater" runat="server">
            <ItemTemplate>
                <%# DataBinder.Eval(Container.DataItem, "username") %> <br />
            </ItemTemplate>
        </asp:Repeater>
    </div>
    <div id="errorMessage" runat="server">
    </div>

    <br />

</asp:Content>
